package toolib.geom;

public class SplineSegment2D extends Line2D {
	
	private int			_index		= -1;
	private Spline2D	_spline		= null;
	
	
	public SplineSegment2D (Spline2D theSpline, int theSegmentIndex) {
		super ();
		_spline = theSpline;
		_index	= theSegmentIndex;
		a		= _spline.vertices ()[theSegmentIndex];
		b		= _spline.vertices ()[theSegmentIndex + 1];
	}
	
	public SplineSegment2D (Spline2D theSpline, float theAX, float theAY, float theBX, float theBY) {
		super (theAX, theAY, theBX, theBY);
		_spline = theSpline;
	}
	
	public SplineSegment2D (Spline2D theSpline, V2f theA, V2f theB) {
		super (theA, theB);
		_spline = theSpline;
	}
	
	public SplineSegment2D (Spline2D theSpline, Line2D theSegment) {
		super (theSegment.a, theSegment.b);
		_spline = theSpline;
	}
	
	public boolean equals (Spline2D theSpline, float theAX, float theAY, float theBX, float theBY) {
		return (_spline == theSpline && a.x == theAX && a.y == theAY && b.x == theBX && b.x == theBY) ? true: false;
	}
	
	public boolean equals (Spline2D theSpline, V2f theA, V2f theB) {
		return (_spline == theSpline && a == theA && b == theB) ? true : false;
	}
	
	public boolean equals (Spline2D theSpline, Line2D theSegment) {
		return (_spline == theSpline && a == theSegment.a && b == theSegment.b) ? true : false;
	}
	
	public int index () {
		if (_index == -1) {
			for (int i=0; i < _spline.vertices ().length - 1; i++) {
				if (a.equals (_spline.vertices ()[i]) && b.equals (_spline.vertices ()[i + 1])) {
					_index = i;
					return i;
				}
			}
		}
		return _index;
	}
	
	public Spline2D spline () {
		return _spline;
	}
	
	public void spline (Spline2D theSpline) {
		_spline = theSpline;
	}
}